import sys
sys.path.append("../")

from services.ZhangTingService import *
from services.CodesService import *

class ZhangTingController:
    def __init__(self,args):
        self.args = args
        self.service = ZhangTingService()
        self.codeService = CodeService()

    def run(self):
        if self.args["func"] == "getAll":
            return self.getAll(self.args)

    def getAll(self,args):
        print(args)
        rs = self.service.getMoreZhangTing(args["num"])
        obj = []
        for row in rs:
            option = {}
            coders = self.codeService.getCode(row["code"])
            codeOption = coders[0]
            option["code"] = row["code"]
            option["codename"] = codeOption["codename"]
            option["industry"] = codeOption["industry"]
            option["gainian"] = codeOption["gainian"]
            shizhi = round(float(codeOption["flow_money"] / 100000000), 2)
            option["flow_money"] = str(shizhi) + "亿元"
            option["pre"] = codeOption["pre_close"]
            option["close"] = codeOption["close"]
            obj.append(option)
        return obj
